package proto

import (
	"regexp"
	D "websocket_apn/define"
	"websocket_apn/log"
)

/*
[DEBUG] [2025/01/03 21:28:47] [PRJ/websocket_apn/main_test.go]:[  197]:   ↑↑↑↑↑ S_GUARD_FAIRY_TREE_FIGHT_RESULT - len:37   2 通关
[DEBUG] [2025/01/03 21:28:47] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 25 00 03 50 DD 00 00 02D4 07 01 81 E2 08 F7 DD F8 04 10 AA 9C 01 20 01 2A 06 08 80 F7 01 20 03
[DEBUG] [2025/01/03 21:28:48] [PRJ/websocket_apn/main_test.go]:[  199]:   ↓↓↓↓↓ S_ACTIVITY_SYNC_CONDITION_LIST_RSP - len:48
[DEBUG] [2025/01/03 21:28:48] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 30 00 00 03 EF 00 00 02D4 07 01 81 E2 0A 1C 08 F7 DD F8 04 12 15 08 92 4E 12 01 32 18 00 20 00 30 00 38 00 40 89 D7 EA E2 C2 32

[DEBUG] [2025/01/03 21:34:26] [PRJ/websocket_apn/main_test.go]:[  197]:   ↑↑↑↑↑ S_GUARD_FAIRY_TREE_FIGHT_RESULT - len:36 2 1关成功
[DEBUG] [2025/01/03 21:34:26] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 24 00 03 50 DD 00 00 02D4 08 94 30 6F 08 F7 DD F8 04 10 A1 9C 01 20 01 2A 05 08 CC 08 20 02
[DEBUG] [2025/01/03 21:35:34] [PRJ/websocket_apn/main_test.go]:[  197]:   ↑↑↑↑↑ S_GUARD_FAIRY_TREE_FIGHT_RESULT - len:29 2 2关失败
[DEBUG] [2025/01/03 21:35:34] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 1D 00 03 50 DD 00 00 02D4 08 94 30 6F 08 F7 DD F8 04 10 A2 9C 01 20 00

[DEBUG] [2025/01/03 21:38:08] [PRJ/websocket_apn/main_test.go]:[  197]:   ↑↑↑↑↑ S_GUARD_FAIRY_TREE_FIGHT_RESULT - len:29 3 1失败
[DEBUG] [2025/01/03 21:38:08] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 1D 00 03 50 DD 00 00 02D4 07 01 81 E2 08 F7 DD F8 04 10 B1 EA 01 20 00

[DEBUG] [2025/01/03 21:39:21] [PRJ/websocket_apn/main_test.go]:[  197]:   ↑↑↑↑↑ S_GUARD_FAIRY_TREE_FIGHT_RESULT - len:36 3 1成功
[DEBUG] [2025/01/03 21:39:21] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 24 00 03 50 DD 00 00 02D4 07 01 81 E2 08 F7 DD F8 04 10 B1 EA 01 20 01 2A 05 08 B0 09 20 03
[DEBUG] [2025/01/03 21:43:48] [PRJ/websocket_apn/main_test.go]:[  197]:   ↑↑↑↑↑ S_GUARD_FAIRY_TREE_FIGHT_RESULT - len:36 3 2成功
[DEBUG] [2025/01/03 21:43:48] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 24 00 03 50 DD 00 00 02D4 07 01 81 E2 08 F7 DD F8 04 10 B2 EA 01 20 01 2A 05 08 B2 14 20 03
[DEBUG] [2025/01/03 21:45:52] [PRJ/websocket_apn/main_test.go]:[  197]:   ↑↑↑↑↑ S_GUARD_FAIRY_TREE_FIGHT_RESULT - len:36 3 3成功
[DEBUG] [2025/01/03 21:45:52] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 24 00 03 50 DD 00 00 02D4 07 01 81 E2 08 F7 DD F8 04 10 B3 EA 01 20 01 2A 05 08 BE 23 20 03

[DEBUG] [2025/01/04 00:24:18] [PRJ/websocket_apn/main_test.go]:[  204]:   PayloadBytes: 71 AB 00 00 00 1C 00 00 43 95 00 00 02D4 07 01 81 E2 08 00 18 BA EA 01 28 C1 B8 02
*/

//解析守卫仙树信息
func ParaGuardFairyTreeInfo(dataBytes []byte) D.GuardFairyTreeInfo {
	var info D.GuardFairyTreeInfo
	if len(dataBytes) < 5 {
		return info
	}
	data := BytesToHexStr(dataBytes)
	// 定义正则表达式                         1 关卡              2                    3
	re := regexp.MustCompile(`18((?:[0-9A-F]{2}){2,3})20([0-9A-F]{2})28((?:[0-9A-F]{2}){2,3})`)
	res := re.FindAllStringSubmatch(data, -1)
	for _, regRes := range res {
		info = D.GuardFairyTreeInfo{
			Level:    regRes[1],                      //关卡
			Now:      OneByteHexStrToByte(regRes[2]), //关卡
			NowLevel: regRes[3],                      //现在的关卡
		}
		break
	}
	// 定义正则表达式                         1 关卡
	re0 := regexp.MustCompile(`18((?:[0-9A-F]{2}){2,3})28((?:[0-9A-F]{2}){1,3})`)
	res0 := re0.FindAllStringSubmatch(data, -1)
	for _, regRes := range res0 {
		info = D.GuardFairyTreeInfo{
			Level:    regRes[1],                                    //关卡
			Now:      byte(ParaIntDataByHexStr(regRes[1]) / 10000), //关卡
			NowLevel: regRes[2],                                    //现在的关卡
		}
		break
	}
	if info.Now == 0 {
		log.Errorf("解析数据失败-%s", data)
	}
	return info
}
